package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.JournalDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Journal;
import com.itheima.service.JournalService;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ldl.plus
 * @date 2020年04月24日  21:48
 * 日志
 */
@Transactional
@Service(interfaceClass = JournalService.class)
public class JournalServiceImpl implements JournalService {

    @Resource
    private JournalDao journalDao;

    @Override
    public void addLog(Journal journal) {
        journalDao.addLog(journal);
    }

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        Integer pageSize = queryPageBean.getPageSize();
        Integer currentPage = queryPageBean.getCurrentPage();
        String queryString = queryPageBean.getQueryString();
        PageHelper.startPage(currentPage, pageSize);
        Page<Journal> page = journalDao.findByCondition(queryString);
        List<Journal> journals = page.getResult();
        long total = page.getTotal();
        return new PageResult(total, journals);
    }
}
